package org.infodavid.common.reflect;

import java.io.Serializable;
import java.util.Comparator;

/**
 * The Class ClassComparator.
 */
public final class ClassComparator implements
Comparator<Class<? extends Object>>, Serializable {

  /** The Constant serialVersionUID. */
  private static final long serialVersionUID = -9109628520208161719L;

  /**
   * Compare the class names of classes represented by two class objects.
   * @param o1 the o1
   * @param o2 the o2
   * @return Return the value returned by {@link java.lang.String#compareTo}
   *         method from java.lang.String class.
   */
  @SuppressWarnings("rawtypes")
  public int compare(final Class o1, final Class o2) {
    int result;

    if (o1 == o2) {
      result = 0;
    }
    else if (o1 == null) {
      result = -1;
    }
    else if (o2 == null) {
      result = 1;
    }
    else {
      result = o1.getName().compareTo(o2.getName());
    }

    return result;
  }
}
